/* $RCSFile: FlashMovie.cs $
 * Apache license v2 2011 by Christian Surieux
 * $Source: ?/ADNCRM.FlashMovie/FlashMovie.cs $
 * $log$
 * Revision 6 2010/08/06 19:56:30  christian.surieux
 *   Added Log to All cs files
 */

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.IO;
using System.Text;
using System.Drawing;
using System.Collections.Specialized;


[assembly: TagPrefix ("AddonNice.UI.WebControls","FlashMovie")]
namespace AddonNice.UI.WebControls
{
	/// <summary>
	/// Flash Movie Control.
	/// </summary>
	[ToolboxData("<{0}:FlashMovie runat=server></{0}:FlashMovie>")]
	[Description ("Flash Movie Control.")]
	[DefaultProperty ("MovieName")]	
	public class FlashMovie : Control, INamingContainer
	{

		#region Control Constructor and Initilization

		/// <summary>
		/// Flash Movie Control.
		/// </summary>
		public FlashMovie() 
		{
			//Initialize default values for prperties
			InitializeControl();
			//Make sure all child controls have been created
			EnsureChildControls();
		}

		/// <summary>
		/// Initializes the default values for members.
		/// </summary>
		protected void InitializeControl() 
		{

			_fsCommandScriptUrl     = string.Empty;
			_mname                  = string.Empty;
			_mautoplay              = true;
			_mquality               = FlashMovieQuality.High;
			_mautoloop              = true;
			_mwmode                 = FlashMovieWindowMode.Window;
			_mscale                 = FlashMovieScale.ShowAll;
			_mflashAlign            = new FlashMovieAlignment(FlashHorizontalAlignment.Center,FlashVerticalAlignment.Center);
			_mhtmlalign             = FlashHtmlAlignment.None;
			_moutputtype            = FlashOutputType.FlashOnly;
			_mmenu                  = true;
			_mdevicefont            = false;
			_mbgcolor               = System.Drawing.Color.White;
			_mwidth                 = "550";
			_mheight                = "400";
			_mLiveConnect           = false;
			_mvariables             = new System.Collections.Specialized.NameValueCollection();
			PostRenderNoScriptContent = string.Empty;
			PostRenderNoFlashContent = string.Empty;
			_mnoflash               = new System.Web.UI.WebControls.PlaceHolder();
			_mnoscript              = new System.Web.UI.WebControls.PlaceHolder();
			_mmajorversion          = 7;
			_mmajorrevision         = 0;
			_mminorversion          = 0;
			_mminorrevision         = 0;
			_mscriptaccesscontrol   = FlashScriptAccessControl.SameDomain;
			_mdetectionalturl       = string.Empty;
			_mdetectioncontenturl   = string.Empty;
			_mallowflashautoinstall = false;
		}

		/// <summary>
		/// Creates the PlaceHolders responsible for containing the controls used in the noscript and noflash rendering methods.
		/// </summary>
		protected override void CreateChildControls() 
		{

			//Create the PlaceHolder that will contain the controls to be rendered 
			//as the noscript content in case javascript is not enabled and plugin 
			//detection is on.
			_mnoscript          = new System.Web.UI.WebControls.PlaceHolder();
			_mnoscript.ID       = FlashMovie.NOSCRIPT_CONTAINERID;
			Controls.Add(_mnoscript);

			//Create the PlaceHolder that will contain the controls to be rendered
			//as the content if the flash plugin was not found or disabled in the
			//client browser.  These controls reside in a javascript else{} block
			//and are wrapped around a document.write(''); JS Statement.
			_mnoflash           = new System.Web.UI.WebControls.PlaceHolder();
			_mnoflash.ID        = FlashMovie.NOFLASH_CONTAINERID;
			Controls.Add(_mnoflash);


			base.CreateChildControls ();
		}
	

		#endregion

		#region  Control Attributes
		/// <summary>
		/// 
		/// </summary>
		private int _mmajorversion;
		/// <summary>
		/// 
		/// </summary>
		private int _mmajorrevision;
		/// <summary>
		/// 
		/// </summary>
		private int _mminorversion;
		/// <summary>
		/// 
		/// </summary>
		private int _mminorrevision;
		/// <summary>
		/// 
		/// </summary>
		private string _fsCommandScriptUrl;
		/// <summary>
		/// 
		/// </summary>
		private FlashScriptAccessControl _mscriptaccesscontrol;
		/// <summary>
		/// 
		/// </summary>
		private string _mdetectionalturl;
		/// <summary>
		/// 
		/// </summary>
		private string _mdetectioncontenturl;
		/// <summary>
		/// 
		/// </summary>
		private bool _mallowflashautoinstall;
		/// <summary>
		/// 
		/// </summary>
		private string _mname;
		/// <summary>
		/// 
		/// </summary>
		private bool _mautoplay;
		/// <summary>
		/// 
		/// </summary>
		private FlashMovieQuality _mquality;
		/// <summary>
		/// 
		/// </summary>
		private bool _mautoloop;
		/// <summary>
		/// 
		/// </summary>
		private FlashMovieWindowMode _mwmode;
		/// <summary>
		/// 
		/// </summary>
		private FlashMovieScale _mscale;
		/// <summary>
		/// 
		/// </summary>
		private FlashMovieAlignment _mflashAlign;
		/// <summary>
		/// 
		/// </summary>
		private FlashHtmlAlignment _mhtmlalign;
		/// <summary>
		/// 
		/// </summary>
		private FlashOutputType _moutputtype;
		/// <summary>
		/// 
		/// </summary>
		private bool _mmenu;
		/// <summary>
		/// 
		/// </summary>
		private bool _mdevicefont;
		/// <summary>
		/// 
		/// </summary>
		private System.Drawing.Color _mbgcolor;
		/// <summary>
		/// 
		/// </summary>
		private string _mwidth;
		/// <summary>
		/// 
		/// </summary>
		private string _mheight;
		/// <summary>
		/// 
		/// </summary>
		private bool _mLiveConnect;
		/// <summary>
		/// 
		/// </summary>
		private System.Collections.Specialized.NameValueCollection _mvariables;
		/// <summary>
		/// 
		/// </summary>
		private System.Web.UI.WebControls.PlaceHolder _mnoscript;
		/// <summary>
		/// 
		/// </summary>
		private System.Web.UI.WebControls.PlaceHolder _mnoflash;
		/// <summary>
		/// The raw HTML content that has been captured after the NoScriptContainer has rendered
		/// </summary>
		protected string PostRenderNoScriptContent;
		/// <summary>
		/// The raw HTML content that has been captured after the NoFlashContainer has rendered
		/// </summary>
		protected string PostRenderNoFlashContent;
		#endregion

		#region Control Constants
		private const string MIME_TYPE = "application/x-shockwave-flash";
		private const string PLUGINS_PAGE = "http://www.macromedia.com/go/getflashplayer";
		private const string PLUGINS_PAGE_SSL = "https://www.macromedia.com/go/getflashplayer";
		private const string DETECTION_PLUGINS_PAGE = "http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
		private const string DETECTION_PLUGINS_PAGE_SSL = "https://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash";
		private const string SCRIPT_VERSION = "javascript1.1";
		private const string CLASS_ID = "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000";
		private const string CODE_BASE_URL = "http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
		private const string CODE_BASE_URL_SSL = "https://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab";
		private const string NOSCRIPT_CONTAINERID = "NoScriptContainer";
		private const string NOFLASH_CONTAINERID = "NoFlashContainer";
		#endregion

		#region Control Properties

		/// <summary>
		/// Gets or sets the major version of the flash plugin to use.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(7)]
		[Description("Determines which flash plugin is needed to play the movie.  The first of four numbers that make up the plugin's codebase.")]
		[Category("Plugin Version")]
		public int MajorPluginVersion{
			get {return _mmajorversion;}
			set {_mmajorversion = value;}
		}

		/// <summary>
		/// Gets or sets the major version revision of the flash plugin to use.  The second of four numbers that make up the plugin's codebase.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(0)]
		[Description("Determines which flash plugin is needed to play the movie.  The second of four numbers that make up the plugin's codebase.")]
		[Category("Plugin Version")]
		public int MajorPluginVersionRevision{
			get {return _mmajorrevision;}
			set {_mmajorrevision = value;}
		}
		/// <summary>
		/// Gets or sets the minor version of the flash plugin to use.  The third of four numbers that make up the plugin's codebase.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(0)]
		[Description("Determines which flash plugin is needed to play the movie.")]
		[Category("Plugin Version")]
		public int MinorPluginVersion{
			get {return _mminorversion;}
			set {_mminorversion = value;}
		}
		/// <summary>
		/// Gets or sets the minor version revision of the flash plugin to use.  The fourth of four numbers that make up the plugin's codebase.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(0)]
		[Description("Determines which flash plugin is needed to play the movie. The fourth of four numbers that make up the plugin's codebase.")]
		[Category("Plugin Version")]
		public int MinorPluginVersionRevision	{
			get {return _mminorrevision;}
			set {_mminorrevision = value;}
		}
		/// <summary>
		/// Gets or sets the flash movie parameter responsible for allowing script access to the movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashScriptAccessControl),"SameDomain")]
		[Description("Determines the allowed script access to the movie")]
		[Category("Movie Control")]
		public FlashScriptAccessControl ScriptAccessControl{
			get {return _mscriptaccesscontrol;}
			set {_mscriptaccesscontrol = value;}
		}

		/// <summary>
		/// Gets or Sets the url of a JavaScript .js file to include in the webpage.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("")]
		[Description("Gets or Sets the url of a JavaScript .js file to include in the webpage.")]
		[Category("Movie Control")]
		[Editor("System.Web.UI.Design.UrlEditor, System.Design",typeof(System.Drawing.Design.UITypeEditor))]
		public string FSCommandScriptUrl {
			get {return _fsCommandScriptUrl;}
			set {_fsCommandScriptUrl = value;}
		}
		/// <summary>
		/// Gets or sets the alternate webpage to redirect to if SWF detection does not detect the flash plugin.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("")]
		[Description("Determines the alternate web page to redirect to if SWF detection does not detect the flash plugin.")]
		[Category("SWF Detection")]
		[Editor("System.Web.UI.Design.UrlEditor, System.Design",typeof(System.Drawing.Design.UITypeEditor))]
		public string SWF_DetectionAltUrl{
			get {
				return (FlashOutputType == FlashOutputType.SWFVersionDetection) ? _mdetectionalturl : "";
			}
			set {_mdetectionalturl = value;}
		}
		/// <summary>
		/// Gets or sets the content webpage to redirect to if SWF detection detects that the flash plugin is installed.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("")]
		[Description("Determines the content web page to redirect to if SWF detection detects that the flash plugin is installed.")]
		[Category("SWF Detection")]
		[Editor("System.Web.UI.Design.UrlEditor, System.Design",typeof(System.Drawing.Design.UITypeEditor))]
		public string SWF_DetectionContentUrl{
			get {
				return (FlashOutputType == FlashOutputType.SWFVersionDetection) ? _mdetectioncontenturl : "";
			}
			set {_mdetectioncontenturl = value;}
		}
		/// <summary>
		/// Gets or sets the flash movie variable used to auto install the plugin.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashScriptAccessControl),"SameDomain")]
		[Description("Determines if the plugin should be auto installed.")]
		[Category("SWF Detection")]
		public bool AllowFlashAutoInstall{
			get {return _mallowflashautoinstall;}
			set {_mallowflashautoinstall = value;}
		}
		/// <summary>
		/// The virtual path to the flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("")]
		[Description("The virtual path to your flash movie.")]
		[Category("Flash Control")]
		[Editor("System.Web.UI.Design.UrlEditor, System.Design",typeof(System.Drawing.Design.UITypeEditor))]
		public string MovieName {
			get {return _mname;}
			set {_mname = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for auto-starting your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(true)]
		[Description("Determines whether or not your flash movie will automatically start at runtime.")]
		[Category("Movie Control")]
		public bool AutoPlay {
			get {return _mautoplay;}
			set {_mautoplay = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for looping your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(true)]
		[Description("Determines whether or not the flash movie will automatically loop infinitely.")]
		[Category("Movie Control")]
		public bool AutoLoop {
			get {return _mautoloop;}
			set {_mautoloop = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for setting the quality of your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashMovieQuality),"High")]
		[Description("Determines the quality setting to use with your flash movie.")]
		[Category("Apperance")]
		public FlashMovieQuality MovieQuality {
			get {return _mquality;}
			set {_mquality = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for setting the window mode of your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashMovieWindowMode),"Window")]
		[Description("Determines the window mode of your flash movie.")]
		[Category("Apperance")]
		public FlashMovieWindowMode WindowMode {
			get {return _mwmode;}
			set {_mwmode = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for setting the scale of your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashMovieScale),"ShowAll")]
		[Description("Determines the scale mode of the flash movie.")]
		[Category("Apperance")]
		public FlashMovieScale MovieScale {
			get {return _mscale;}
			set {_mscale = value;}
		}

		/// <summary>
		/// Gets or sets the flash horizontal alignment for your movie.
		/// Used in conjunction with the FlashVerticalAlignment property to form the flash "salign" parameter.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[Description("Determines the flash horizontal alignment setting for use in the salign parameter.")]
		[Category("Alignment")]
		public FlashHorizontalAlignment FlashHorizontalAlignment {
			get {return _mflashAlign.HorizontalAlign;}
			set {_mflashAlign.HorizontalAlign = value;}
		}

		/// <summary>
		/// Gets or sets the flash vertical alignment for your movie.
		/// Used in conjunction with the FlashHorizontalAlignment property to form the flash "salign" parameter.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[Description("Determines the flash vertical alignment setting for use in the salign parameter.")]
		[Category("Alignment")]
		public FlashVerticalAlignment FlashVerticalAlignment {
			get {return _mflashAlign.VerticalAlign;}
			set {_mflashAlign.VerticalAlign = value;}
		}

		/// <summary>
		/// Gets the value to be used in the flash salign parameter from both the FlashHorizontalAlignment and FlashVerticalAlignment properties.
		/// </summary>
		[Browsable(false)]
		protected string FlashAlignment {
			get {return _mflashAlign.ToString();}
		}

		/// <summary>
		/// Gets or sets the html alignment for your flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashHtmlAlignment),"None")]
		[Description("Determines the html alignment of your flash movie.")]
		[Category("Alignment")]
		public FlashHtmlAlignment HtmlAlignment {
			get {return _mhtmlalign;}
			set {_mhtmlalign = value;}
		}

		/// <summary>
		/// Gets or sets the flash output type to use when rendering the FlashMovie control to the browser.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(AddonNice.UI.WebControls.FlashOutputType),"FlashOnly")]
		[Description("Determines the output type to use when rendering the FlashMovie control to the browser.")]
		[Category("Movie Control")]
		public FlashOutputType FlashOutputType {
			get {return _moutputtype;}
			set {_moutputtype = value;}
		}
		/// <summary>
		/// Gets or sets the flash movie parameter responsible for setting the menu mode of your flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(true)]
		[Description("Determines the menu mode of your flash movie.")]
		[Category("Movie Control")]
		public bool ShowMenu {
			get {return _mmenu;}
			set {_mmenu = value;}
		}

		/// <summary>
		/// Gets or sets the flash movie parameter responsible for enabling or disabling device fonts in your movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(false)]
		[Description("Determines if your flash movie will use device fonts.")]
		[Category("Apperance")]
		public bool UseDeviceFonts {
			get {return _mdevicefont;}
			set {_mdevicefont = value;}
		}

		/// <summary>
		/// Gets or sets the background color of your flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(typeof(System.Drawing.Color),"#ffffff")]
		[Description("Determines the background color of your flash movie.")]
		[Category("Apperance")]
		public Color MovieBGColor {
			get {return _mbgcolor;}
			set {_mbgcolor = value;}
		}

		/// <summary>
		/// Gets or sets the width of your flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("550")]
		[Description("Determines the width of your flash movie.")]
		[Category("Apperance")]
		public string MovieWidth {
			get {return _mwidth;}
			set {_mwidth = value;}
		}

		/// <summary>
		/// Gets or sets the height of your flash movie.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue("400")]
		[Description("Determines the height of your flash movie.")]
		[Category("Apperance")]
		public string MovieHeight {
			get {return _mheight;}
			set {_mheight = value;}
		}

		/// <summary>
		/// Gets or sets the html embed element's swLiveConnect parameter.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[DefaultValue(false)]
		[Description("Sets the html embed element's swLiveConnect parameter.")]
		[Category("Movie Control")]
		public bool LiveConnect{
			get {return _mLiveConnect;}
			set {_mLiveConnect = value;}
		}

		/// <summary>
		/// Gets or sets the NameValueCollection used to pass variables to the flash movie through the querystring.
		/// </summary>
		[Browsable(false)]
		public NameValueCollection MovieVariables {
			get {return _mvariables;}
			set {_mvariables = value;}
		}

		/// <summary>
		/// Gets or sets the PlaceHolder responsible for containing the controls that will be rendered as the html noscript 
		/// content if javascript is disabled on the client browser.  This is only relevent if the FlashMovie controls output
		///  type is set to one of the version detection enumeration members.
		/// </summary>
		[Browsable(false)]
		public PlaceHolder NoScriptContainer {
			get {return _mnoscript;}
			set {_mnoscript = value;}
		}

		/// <summary>
		/// Gets or sets the PlaceHolder responsible for containing the controls that will be rendered as the javascript 
		/// content if no flash plugin was detected on the client browser.  This is only relevent if the FlashMovie controls output
		///  type is set to one of the version detection enumeration members.
		/// </summary>
		[Browsable(false)]
		public PlaceHolder NoFlashContainer {
			get {return _mnoflash;}
			set {_mnoflash = value;}
		}

		/// <summary>
		/// Gets the mimetype of the flash plugin.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
		[Description("The mime type that the flash plugin uses.")]
		[Category("Constants")]
		public string FlashMimeType {
			get {return FlashMovie.MIME_TYPE;}
		}

		/// <summary>
		/// Gets the CLASSID of the flash plugin.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
		[Description("The classid of the flash plugin.")]
		[Category("Constants")]
		public string FlashClassID {
			get {return FlashMovie.CLASS_ID;}
		}

		/// <summary>
		/// Gets the CodeBase Url used as the codebase parameter to the flash object.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
		[Description("The codebase url used in the codebase parameter to the flash object.")]
		[Category("Constants")]
		public string FlashCodeBase {
			get 
			{
				if ( System.Web.HttpContext.Current.Request.IsSecureConnection ||
					MovieName.IndexOf ( "https" ) == 0 ) 
				{
					return FlashMovie.CODE_BASE_URL_SSL + "#version=" + VersionString;
				}
				else
				{
					return FlashMovie.CODE_BASE_URL + "#version=" + VersionString;
				}
			}
		}

		/// <summary>
		/// Gets the flash plugins webpage url that is used in the embed element.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
	 	[Description("The url of the flash plugins page used in the html embed element.")]
		[Category("Constants")]
		public string FlashPluginsPage 
		{
			get 
			{
				if ( System.Web.HttpContext.Current.Request.IsSecureConnection ||
					MovieName.IndexOf ( "https" ) == 0 ) 
				{
					return FlashMovie.PLUGINS_PAGE_SSL;
				}
				else
				{
					return FlashMovie.PLUGINS_PAGE;
				}
			}
		}

		/// <summary>
		/// Gets the flash plugins webpage url that is used with SWF version detection.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
		[Description("The url of the flash plugins page used with SWF version detection.")]
		[Category("Constants")]
		public string DetectionPluginsPage
		{
			get 
			{
				if ( System.Web.HttpContext.Current.Request.IsSecureConnection ||
					MovieName.IndexOf ( "https" ) == 0 ) 
				{
					return FlashMovie.DETECTION_PLUGINS_PAGE_SSL;
				}
				else
				{
					return FlashMovie.DETECTION_PLUGINS_PAGE;
				}
			}
		}
		/// <summary>
		/// Gets the javascript version used to detect the falsh plugin version.
		/// </summary>
		[Browsable(true)]
		[Bindable(false)]
		[ReadOnly(true)]
		[Description("The javascript version used to detect the flash plugin version.")]
		[Category("Constants")]
		public string ClientScriptVersion {
			get {return FlashMovie.SCRIPT_VERSION;}
		}

		/// <summary>
		/// Gets the full version string of the plugin.  Used in the plugins codebase.
		/// </summary>
		[Browsable(false)]
		public string VersionString{
			get 
			{
				return MajorPluginVersion + "," + MajorPluginVersionRevision + "," + 
											MinorPluginVersion + "," + MinorPluginVersionRevision; 
			}
		}


		#endregion

		#region Control Render Methods
		/// <summary>
		/// Captures and supresses the porting of the rendered content of the noscript and noflash containers to the HtmlTextWriter.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected override void RenderChildren(HtmlTextWriter writer) 
		{

			//Loop through controls to find the NoScript and NoFlash placeholders
			//Content of these controls is stored and suppressed from the HtmlTextWriter
			//For further modifications
			foreach(Control c in Controls)	
			{
				StringWriter sw = new StringWriter();
				HtmlTextWriter htw = new HtmlTextWriter(sw);

				c.RenderControl(htw);
				StringBuilder sb = sw.GetStringBuilder();

				if(c.ID == (FlashMovie.NOFLASH_CONTAINERID) )
				{
					PostRenderNoFlashContent = sb.ToString();
				}
				else if(c.ID == (FlashMovie.NOSCRIPT_CONTAINERID) )
				{
					PostRenderNoScriptContent = sb.ToString();
				}
			}

			
		}
	
		/// <summary>
		/// Renders the FlashMovie Control
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected override void Render(HtmlTextWriter writer) 
		{
			//Calls RenderChildren to make sure NoScript and NoFlash Content is captured.
			RenderChildren(writer);

			//Render out the script tag used to include the FSCommand functions is nessesary
			if (FSCommandScriptUrl != string.Empty) 
			{
				writer.WriteLine("<script language=\"javascript\" src=\"{0}\"></script>", FSCommandScriptUrl);
			}

			//Initiate the flash output method
			switch(FlashOutputType)
			{
				case FlashOutputType.ClientScriptVersionDection:
					RenderPluginDetectionScript(writer);
					break;
				case FlashOutputType.SWFVersionDetection :
					RenderSWFDetectionScript(writer);
					break;
				case FlashOutputType.FlashOnly :
					RenderFlashOnlyScript(writer);
					break;
				default:
					RenderFlashOnlyScript(writer);
					break;
			}

			//Suppressed so that Render children is not called twice.
			//base.Render (writer);
		}

		/// <summary>
		/// Renders the flash movie parameters to the html object tag.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected virtual void RenderFlashObjectParameters(HtmlTextWriter writer)
		{

			writer.Write("<PARAM NAME=movie VALUE=\"" + MovieName);
			RenderFlashMovieVariables(writer);
			writer.Write("\"> ");
			
			//
			//Only set parameters that are not set to the flash plugin default value
			//
			if(AutoPlay == false) {	writer.Write("<PARAM NAME=play VALUE=" + AutoPlay.ToString().ToLower() + " /> "); }
			if(AutoLoop == false) {	writer.Write("<PARAM NAME=loop VALUE=" + AutoLoop.ToString().ToLower() + " /> "); }
			if(ShowMenu == false) {	writer.Write("<PARAM NAME=menu VALUE=" + ShowMenu.ToString().ToLower() + " /> "); }
			if(MovieScale != FlashMovieScale.ShowAll) {	writer.Write("<PARAM NAME=scale VALUE=" + MovieScale.ToString().ToLower() + " /> "); }
			if(WindowMode != FlashMovieWindowMode.Window) {	writer.Write("<PARAM NAME=wmode VALUE=" + WindowMode.ToString().ToLower() + " /> ");}
			if(UseDeviceFonts == true) {	writer.Write("<PARAM NAME=devicefont VALUE=" + UseDeviceFonts.ToString().ToLower() + " /> "); }
			if(FlashAlignment.ToString() != "") { writer.Write("<PARAM NAME=salign VALUE=" + FlashAlignment.ToString() + " /> "); }

			
			writer.Write("<PARAM NAME=quality VALUE=" + MovieQuality.ToString() + "/> ");
			writer.Write("<PARAM NAME=bgcolor VALUE=#" + MovieBGColor.ToArgb().ToString("x").Substring(2) + "/> ");
			writer.Write("<PARAM NAME=\"allowScriptAccess\" value=\"" + ScriptAccessControl + "\" />");


		}
		/// <summary>
		/// Renders the flash movie parameters to the html embed tag.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected virtual void RenderFlashEmbedParameters(HtmlTextWriter writer)
		{

			//
			//Only set parameters that are not set to the flash plugin default value
			//
			if(AutoPlay == false) { writer.Write("play=\"" + AutoPlay.ToString().ToLower() + "\" "); }
			if(AutoLoop == false) { writer.Write("loop=\"" + AutoLoop.ToString().ToLower() + "\" "); }
			if(ShowMenu == false) { writer.Write("menu=\"" + ShowMenu.ToString().ToLower() + "\" "); }
			if(MovieScale != FlashMovieScale.ShowAll) { writer.Write("scale=\"" + MovieScale.ToString().ToLower() + "\" "); }
			if(WindowMode != FlashMovieWindowMode.Window) { writer.Write("wmode=\"" + WindowMode.ToString().ToLower() + "\" "); }
			if(UseDeviceFonts == true) {	writer.Write("devicefont=\"" + UseDeviceFonts.ToString().ToLower() + "\" ");	}
			if(FlashAlignment.ToString() != "") {writer.Write("salign=\"" + FlashAlignment.ToString() + "\" ");}
			
			writer.Write("quality=\"" + MovieQuality.ToString().ToLower() + "\" ");
			writer.Write("bgcolor=\"#" + MovieBGColor.ToArgb().ToString("x").Substring(2) + "\" ");
			writer.Write("allowScriptAccess=\"" + ScriptAccessControl + "\" ");
		}
		/// <summary>
		/// Renders the NameValueCollection of flash movie variables into querystring form.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected virtual void RenderFlashMovieVariables(HtmlTextWriter writer)
		{
			if(MovieVariables.Count > 0)
			{
				string varString = "";
				//Start querystring begining
				writer.Write("?");

				foreach(string s in MovieVariables.Keys)
				{
					//writes key name value pair
					varString += s + "=" + MovieVariables[s] + "&";
				}
				
				//strip off last ampersand
				varString = varString.Remove(varString.Length-1,1);
				writer.Write(varString);
			}
		}
		/// <summary>
		/// If plugin version detection is enabled this method is called to invoke the rendering of the FlashMovie control.
		/// </summary>
		protected void RenderPluginDetectionScript(HtmlTextWriter writer)
		{

			//No movie UI is available during client script detection
			//because of the javascript code.  So if the state is in 
			//design mode the FlashOnlyScript method will be rendered to give
			//the user some UI to view.
			if((Site != null)&&(Site.DesignMode == true))
			{
				RenderFlashOnlyScript(writer);
			}
			else
			{
				//Open client script
				writer.WriteLine("<SCRIPT LANGUAGE=JavaScript1.1>");
				writer.WriteLine("<!--");

				//Render plugin detection and movie display handlers
				RenderPluginDetectionDeclaration(writer,MajorPluginVersion);
				RenderPluginDetectionBlock(writer);
				RenderContentDisplayBlock(writer);

				//Close client script
				writer.WriteLine("//-->");
				writer.WriteLine("</SCRIPT>");

				//Render NoScript content
				writer.WriteLine("<NOSCRIPT>");
				writer.Write(PostRenderNoScriptContent);
				writer.WriteLine("</NOSCRIPT>");
			}
		}
		/// <summary>
		/// If FlashOnly output method is set this method is called to invoke the rendering of the FlashMovie control.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected void RenderFlashOnlyScript(HtmlTextWriter writer)
		{
			//Start html object tag
			writer.WriteLine("<OBJECT classid=\"" + FlashMovie.CLASS_ID + "\"");
			writer.WriteLine("codebase=\"" + FlashCodeBase + "\"");

			writer.Write("WIDTH=\"" + MovieWidth + "\" HEIGHT=\"" + MovieHeight + "\" ");
			writer.Write("id=\"" + ID + "\" ALIGN=\"" + HtmlAlignment.ToString().ToLower() + "\">");
			RenderFlashObjectParameters(writer);

			//Start html embed tag
			writer.Write("<EMBED src=\"" + MovieName);
			RenderFlashMovieVariables(writer);
			writer.Write("\" ");

			RenderFlashEmbedParameters(writer);

			writer.Write("WIDTH=\"" + MovieWidth + "\" HEIGHT=\"" + MovieHeight + "\" ");
			writer.WriteLine("id=\"" + ID + "\" ALIGN=\"" + HtmlAlignment.ToString().ToLower() + "\"");

			writer.Write("TYPE=\"" + FlashMovie.MIME_TYPE + "\" ");
			writer.WriteLine("PLUGINSPAGE=\"" + FlashMovie.PLUGINS_PAGE + "\"></EMBED>");
	
			writer.WriteLine("</OBJECT>");
		}

		/// <summary>
		/// If SWF Detection in output method is set this method is called to invoke the rendering of the FlashMovie control.
		/// </summary>
		/// <param name="writer"></param>
		protected void RenderSWFDetectionScript(HtmlTextWriter writer)
		{

			MovieVariables.Add("contentVersion",Convert.ToString(MajorPluginVersion));
			MovieVariables.Add("contentMajorRevision","0");
			MovieVariables.Add("contentMinorRevision",Convert.ToString(MinorPluginVersion));
			MovieVariables.Add("allowFlashAutoInstall",AllowFlashAutoInstall.ToString());

			//Hides output from designer.
			//Problems with redirection taking place made designer
			//a little quirky.
			if((Site != null)&&(Site.DesignMode == true)){}
			else
			{
				MovieVariables.Add("flashContentURL",SWF_DetectionContentUrl);
				MovieVariables.Add("altContentURL",SWF_DetectionAltUrl);
			}

			writer.Write("<object classid=\"" + FlashClassID + "\" ");
			writer.Write("codebase=\"" + FlashMovie.CODE_BASE_URL + "\" ");
			writer.WriteLine("width=\"" + MovieWidth  + "\" height=\"" + MovieHeight + "\">");

			RenderFlashObjectParameters(writer);

			//Start html embed tag
			writer.Write("<embed src=\"" + MovieName);
			RenderFlashMovieVariables(writer);
			writer.Write("\" ");

			RenderFlashEmbedParameters(writer);
			writer.Write("width=\"" + MovieWidth + "\" height=\"" + MovieHeight + "\" ");

			writer.Write("type=\"" + FlashMovie.MIME_TYPE + "\" ");
			writer.WriteLine("pluginspage=\"" + FlashMovie.DETECTION_PLUGINS_PAGE + "\"></embed>");

			writer.WriteLine("</object>");
		}

		#endregion

		#region Helper Methods For Rendering Flash Movie In Detection Mode
		/// <summary>
		/// Renders the client script variable initilization and sets the plugin client script variable
		/// </summary>
		/// <param name="writer">If plugin version detection is enabled this method is called to invoke the rendering of the FlashMovie control.</param>
		/// <param name="version">The version number being used for plugin detection.</param>
		protected virtual void RenderPluginDetectionDeclaration(HtmlTextWriter writer, int version)
		{
			writer.WriteLine("var MM_contentVersion = " + version + ";");
			writer.WriteLine("var plugin = (navigator.mimeTypes && navigator.mimeTypes[\"" + FlashMovie.MIME_TYPE + "\"]) ?");
			writer.WriteLine("navigator.mimeTypes[\"" + FlashMovie.MIME_TYPE + "\"].enabledPlugin : 0;");
		}

		/// <summary>
		/// Renders the client script that detects if the flash plugin is available
		/// </summary>
		protected virtual void RenderPluginDetectionBlock(HtmlTextWriter writer){
			writer.WriteLine("if ( plugin ) {");
			writer.WriteLine("var words = navigator.plugins[\"Shockwave Flash\"].description.split(\" \");");
			writer.WriteLine("for (var i = 0; i < words.length; ++i)");
			writer.WriteLine("{");
			writer.WriteLine("if (isNaN(parseInt(words[i])))");
			writer.WriteLine("continue;");
			writer.WriteLine("var MM_PluginVersion = words[i];");
			writer.WriteLine("}");
			writer.WriteLine("var MM_FlashCanPlay = MM_PluginVersion >= MM_contentVersion;");
			writer.WriteLine("}");
			writer.WriteLine("else if (navigator.userAgent && navigator.userAgent.indexOf(\"MSIE\")>=0");
			writer.WriteLine("&& (navigator.appVersion.indexOf(\"Win\") != -1)) {");
			writer.WriteLine(@"document.write('<SCR' + 'IPT LANGUAGE=VBScript\> \n');");
			writer.WriteLine(@"document.write('on error resume next \n');");
			writer.Write("document.write('MM_FlashCanPlay = ( IsObject(CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" & MM_contentVersion)))");
			writer.WriteLine(@"\n');");
			writer.WriteLine(@"document.write('</SCR' + 'IPT\> \n');");
			writer.WriteLine("}");
		}

		/// <summary>
		/// Renders the client script and content used to display the flash movie.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected virtual void RenderFlashCanPlayBlock(HtmlTextWriter writer){
			writer.WriteLine("document.write('<OBJECT classid=\"" + FlashMovie.CLASS_ID + "\"');");
			writer.WriteLine("document.write('  codebase=\"" + FlashCodeBase + "\" ');");
			writer.Write("document.write(' ");
			writer.Write("ID=\"" + ID + "\" WIDTH=\"" + MovieWidth + "\" ");
			writer.WriteLine("HEIGHT=\"" + MovieHeight + "\" ALIGN=\"" + HtmlAlignment.ToString().ToLower() + "\">');");

			writer.Write("document.write(' ");
			RenderFlashObjectParameters(writer);
			writer.WriteLine("  ');");


			writer.Write("document.write(' <EMBED src=\"" + MovieName);
			RenderFlashMovieVariables(writer);
			writer.Write("\" ");

			RenderFlashEmbedParameters(writer);
			writer.WriteLine("  ');");

			writer.Write("document.write(' swLiveConnect=" + LiveConnect.ToString().ToUpper() + " ");
			writer.Write("WIDTH=\"" + MovieWidth + "\" HEIGHT=\"" + MovieHeight + "\" ");
			writer.Write("NAME=\"" + MovieName );
			RenderFlashMovieVariables(writer);
			writer.WriteLine("\" ALIGN=\"" + HtmlAlignment.ToString().ToLower() + "\"');");
			writer.WriteLine("document.write(' TYPE=\"" + FlashMimeType + "\" PLUGINSPAGE=\"" + FlashPluginsPage + "\">');");
			writer.WriteLine("document.write(' </EMBED>');");


			writer.WriteLine("document.write(' </OBJECT>');");
		}

		/// <summary>
		/// Renders the client script and content used if the flash plugin is unavailable.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected void RenderFlashCanNotPlayBlock(HtmlTextWriter writer){

			if(_mnoflash.HasControls()){
				string line = "";

				StringReader sr = new StringReader(PostRenderNoFlashContent.Replace(@"\",@"\\").Replace("'",@"\'"));
				while((line = sr.ReadLine())!=null){
					writer.Write("document.write('");
					writer.Write(line);
					writer.WriteLine("');");
				}
			}

		}
	
		/// <summary>
		/// Renders the top level client script used to display content to the browser.
		/// </summary>
		/// <param name="writer">The HtmlTextWriter to render content to.</param>
		protected virtual void RenderContentDisplayBlock(HtmlTextWriter writer){
			writer.WriteLine("if ( MM_FlashCanPlay ) {");
			RenderFlashCanPlayBlock(writer);
			writer.WriteLine("} else{");
			RenderFlashCanNotPlayBlock(writer);
			writer.WriteLine("}");
		}

		#endregion

		#region ViewState Methods

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		protected override object SaveViewState()
		{
			// Get the base state object
			object baseState = base.SaveViewState();

			// Create the array to hold all stated data
			object[] allStates = new object[27];

			// Set the first index of the state array to the base state
			allStates[0] = baseState;

			allStates[1]	= AllowFlashAutoInstall;
			allStates[2]	= AutoLoop;
			allStates[3]	= AutoPlay;
			allStates[4]	= FlashHorizontalAlignment;
			allStates[5]	= FlashOutputType;
			allStates[6]	= FlashVerticalAlignment;
			allStates[7]	= FSCommandScriptUrl;
			allStates[8]	= HtmlAlignment;
			allStates[9]	= LiveConnect;
			allStates[10]	= MajorPluginVersion;
			allStates[11]	= MajorPluginVersionRevision;
			allStates[12]	= MinorPluginVersion;
			allStates[13]	= MinorPluginVersionRevision;
			allStates[14]	= MovieBGColor;
			allStates[15]	= MovieHeight;
			allStates[16]	= MovieName;
			allStates[17]	= MovieQuality;
			allStates[18]	= MovieScale;
			allStates[19]	= MovieVariables;
			allStates[20]	= MovieWidth;
			allStates[21]	= ScriptAccessControl;
			allStates[22]	= ShowMenu;
			allStates[23]	= SWF_DetectionAltUrl;
			allStates[24]	= SWF_DetectionContentUrl;
			allStates[25]	= UseDeviceFonts;
			allStates[26]	= WindowMode;

			return allStates;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="savedState"></param>
		protected override void LoadViewState(object savedState)
		{
			if (savedState != null)
			{
				// Load State from the array of objects that was saved at SavedViewState.
				object[] baseState = (object[]) savedState;

				if (baseState[0] != null)
					base.LoadViewState(baseState[0]);

				if (baseState[1] != null)
					AllowFlashAutoInstall = (bool) baseState[1];
				
				if (baseState[2] != null)
					AutoLoop = (bool) baseState[2];
				
				if (baseState[3] != null)
					AutoPlay = (bool) baseState[3];
				
				if (baseState[4] != null)
					FlashHorizontalAlignment = (FlashHorizontalAlignment) baseState[4];
				
				if (baseState[5] != null)
					FlashOutputType = (FlashOutputType) baseState[5];
				
				if (baseState[6] != null)
					FlashVerticalAlignment = (FlashVerticalAlignment) baseState[6];
				
				if (baseState[7] != null)
					FSCommandScriptUrl = (string) baseState[7];
				
				if (baseState[8] != null)
					HtmlAlignment = (FlashHtmlAlignment) baseState[8];
				
				if (baseState[9] != null)
					LiveConnect = (bool) baseState[9];
				
				if (baseState[10] != null)
					MajorPluginVersion = (int) baseState[10];
				
				if (baseState[11] != null)
					MajorPluginVersionRevision = (int) baseState[11];
				
				if (baseState[12] != null)
					MinorPluginVersion = (int) baseState[12];
				
				if (baseState[13] != null)
					MinorPluginVersionRevision = (int) baseState[13];
				
				if (baseState[14] != null)
					MovieBGColor = (Color) baseState[14];
				
				if (baseState[15] != null)
					MovieHeight = (string) baseState[15];
				
				if (baseState[16] != null)
					MovieName = (string) baseState[16];
				
				if (baseState[17] != null)
					MovieQuality = (FlashMovieQuality) baseState[17];
				
				if (baseState[18] != null)
					MovieScale = (FlashMovieScale) baseState[18];
				
				if (baseState[19] != null)
					MovieVariables = (NameValueCollection) baseState[19];
				
				if (baseState[20] != null)
					MovieWidth = (string) baseState[20];
				
				if (baseState[21] != null)
					ScriptAccessControl = (FlashScriptAccessControl) baseState[21];
				
				if (baseState[22] != null)
					ShowMenu = (bool) baseState[22];
				
				if (baseState[23] != null)
					SWF_DetectionAltUrl = (string) baseState[23];
				
				if (baseState[24] != null)
					SWF_DetectionContentUrl = (string) baseState[24];
				
				if (baseState[25] != null)
					UseDeviceFonts = (bool) baseState[25];
				
				if (baseState[26] != null)
					WindowMode = (FlashMovieWindowMode) baseState[26];

			}
		}


		#endregion

	}
}
